  
import { observable, action } from "mobx";

import { ITag } from '../utils/interface';


class Util{
    @observable 
    tags:ITag [] = [];
    @observable
    active = 0;

    /* 添加标签 */
    @action 
    addTag(tag: ITag){
        let index = this.tags.findIndex(item=>item.path === tag.path);
        console.log('index..',index);
        
        if (index === -1){
            this.tags.push(tag);
        }else{
            this.active = index;
        }
    }

    /* 切换高亮 */
    @action
    changeTag(index: number){
        this.active = index;
    }

    /* 移除标签 */
    @action 
    removeTag(tag: ITag){
        let index = this.tags.findIndex(item=>item.path === tag.path);
        if (index !== -1){
            this.tags.splice(index, 1);
        }
    }
}

export default Util;